package {
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.FP;

	public class PhysicsEntity extends Entity {
		protected var xSpeed : Number = 0;
		protected var ySpeed : Number = 0;
		protected var onTheGround : Boolean = false;
		protected var gravity : Number = 0.3;

		public function PhysicsEntity() {
		}

		override public function update() : void {
			ySpeed += gravity;
			adjustXPosition();
			adjustYPosition();
		}
		import net.flashpunk.utils.Input;
		import net.flashpunk.utils.Key;

		protected function adjustXPosition() : void {
			for (var i : int = 1; i < Math.abs(xSpeed); i++) {
				if (!collide("solid", x + FP.sign(xSpeed), y)) {
					x += FP.sign(xSpeed);
				} else {
					xSpeed = 0;
					break;
				}
			}
		}

		protected function adjustYPosition() : void {
			for (var i : int = 0; i < Math.abs(ySpeed); i++) {
				if (!collide("solid", x, y + FP.sign(ySpeed))) {
					y += FP.sign(ySpeed);
					onTheGround = false;
				} else {
					if (ySpeed > 0) {
						onTheGround = true;
					}
					ySpeed = 0;
					break;
				}
			}
		}
	}
}
